From: Paul Donald Date: Fri, 3 Oct 2025 14:36:03 +0000 (+0200) Subject: config: drop double size lease times; they are all UINT32_MAX; X-Git-Url: http://git.openwrt.org/%22https:/collectd.org//%22/%22https:/collectd.org/%22?a=commitdiff_plain;h=93449f1513b47bdc373112ac2be7ac08766a82b1;p=project%2Fodhcpd.git config: drop double size lease times; they are all UINT32_MAX; This now prevents implicit 64 bit->32 bit truncation which may flag compiler errors later on down the road. All of the variables receiving from parse_leasetime() are uint32_t anyway, so max 136 years of valid lease time will have to suffice :) Signed-off-by: Paul Donald Link: https://github.com/openwrt/odhcpd/pull/225 Signed-off-by: Álvaro Fernández Rojas --- diff --git a/src/config.c b/src/config.c index ae6675c..7f11281 100644 --- a/src/config.c +++ b/src/config.c @@ -431,9 +431,9 @@ static void set_config(struct uci_section *s) } } -static double parse_leasetime(struct blob_attr *c) { +static uint32_t parse_leasetime(struct blob_attr *c) { char *val = blobmsg_get_string(c), *endptr = NULL; - double time = strcmp(val, "infinite") ? strtod(val, &endptr) : UINT32_MAX; + uint32_t time = strcmp(val, "infinite") ? (uint32_t)strtod(val, &endptr) : UINT32_MAX; if (time && endptr && endptr[0]) { switch(endptr[0]) { @@ -452,7 +452,7 @@ static double parse_leasetime(struct blob_attr *c) { return time; err: - return -1; + return 0; } static void free_lease(struct lease *l) @@ -585,8 +585,8 @@ int set_lease_from_blobmsg(struct blob_attr *ba) } if ((c = tb[LEASE_ATTR_LEASETIME])) { - double time = parse_leasetime(c); - if (time < 0) + uint32_t time = parse_leasetime(c); + if (time == 0) goto err; l->leasetime = time; @@ -1061,9 +1061,9 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->no_dynamic_dhcp = !blobmsg_get_bool(c); if ((c = tb[IFACE_ATTR_LEASETIME])) { - double time = parse_leasetime(c); + uint32_t time = parse_leasetime(c); - if (time >= 0) + if (time > 0) iface->dhcp_leasetime = time; else syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", @@ -1072,25 +1072,25 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr } if ((c = tb[IFACE_ATTR_MAX_PREFERRED_LIFETIME])) { - double time = parse_leasetime(c); + uint32_t time = parse_leasetime(c); - if (time >= 0) { + if (time > 0) iface->max_preferred_lifetime = time; - } else { + else syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", iface_attrs[IFACE_ATTR_MAX_PREFERRED_LIFETIME].name, iface->name); - } + } if ((c = tb[IFACE_ATTR_MAX_VALID_LIFETIME])) { - double time = parse_leasetime(c); + uint32_t time = parse_leasetime(c); - if (time >= 0) { + if (time > 0) iface->max_valid_lifetime = time; - } else { + else syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", iface_attrs[IFACE_ATTR_MAX_VALID_LIFETIME].name, iface->name); - } + } if ((c = tb[IFACE_ATTR_START])) {